<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>替换字符串中的字符 - replace()</title>
</head>

<body>
    <p>单击按钮将段落中的第一个 Microsoft 替换成 Runoob：</p>
    <p id="demo">Visit Microsoft!Visit Microsoft!</p>
    <button onclick="myFunction()">点我</button>
    <script>
        function myFunction() {
            var str = document.getElementById("demo").innerHTML;
            var n = str.replace("Micsoft", "Runoob");
            document.getElementById("demo").innerHTML = n;
        }
    </script>
</body>

</html>